﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace DownloadPlug_ins
{
    public partial class Config : Form
    {
        public Common2 common = new Common2();
        public Config()
        {
            InitializeComponent();

            this.cCombox1.DataSource = GetData();
            this.cCombox1.ValueMember = "value";
            this.cCombox1.DisplayMember = "name";

            this.cCombox2.DataSource = GetData();
            this.cCombox2.ValueMember = "value";
            this.cCombox2.DisplayMember = "name";
            Init();
        }
        public DataTable GetData()
        {
            DataTable dt = new DataTable();
            dt.Columns.Add("name");
            dt.Columns.Add("value");

            DataRow dr = dt.NewRow();
            dr[0] = "每天";
            dr[1] = 1;
            dt.Rows.Add(dr);

            dr = dt.NewRow();
            dr[0] = "每10小时";
            dr[1] = 7;
            dt.Rows.Add(dr);


            dr = dt.NewRow();
            dr[0] = "每5小时";
            dr[1] = 8;
            dt.Rows.Add(dr);

            dr = dt.NewRow();
            dr[0] = "每小时";
            dr[1] = 2;
            dt.Rows.Add(dr);


            dr = dt.NewRow();
            dr[0] = "每40分钟";
            dr[1] = 3;
            dt.Rows.Add(dr);


            dr = dt.NewRow();
            dr[0] = "每30分钟";
            dr[1] = 4;
            dt.Rows.Add(dr);

            dr = dt.NewRow();
            dr[0] = "每15分钟";
            dr[1] = 5;

            dt.Rows.Add(dr);
            dr = dt.NewRow();
            dr[0] = "每5分钟";
            dr[1] = 6;
            dt.Rows.Add(dr);



            return dt;
        }


        public void Init()
        {
            ConfigModel model = common.GetXml();//获取相关配置属性
            this.ctxtAccount.Text = model.UserName;
            this.ctxtDatabaseName.Text = model.DataBase;
            this.ctxtPassWord.Text = model.PassWord;
            this.ctxtServer.Text = model.Server;
            this.ctxtWebService.Text = model.WebService;
            this.cCombox1.SelectedValue = model.ServerType;


            this.ctxtAccount2.Text = model.UserName2;
            this.ctxtDatabaseName2.Text = model.DataBase2;
            this.ctxtPassWord2.Text = model.PassWord2;
            this.ctxtServer2.Text = model.Server2;
        }

        private void gbtnSetDb_Click(object sender, EventArgs e)
        {
            string account = this.ctxtAccount.Text;
            string dataBase = this.ctxtDatabaseName.Text;
            string passWord = this.ctxtPassWord.Text;
            string server = this.ctxtServer.Text;

            common.SetXml("Server", server, "Source");
            common.SetXml("Account", account, "Source");
            common.SetXml("PassWord", passWord, "Source");
            common.SetXml("DatabaseName", dataBase, "Source");
            MessageBox.Show("操作成功！");
        }

        private void gbtnSetWeb_Click(object sender, EventArgs e)
        {
            string webService = this.ctxtWebService.Text;
            string serverType = this.cCombox1.SelectedValue.ToString();
            string serverType2 = this.cCombox2.SelectedValue.ToString();
            common.SetXml("WebService", webService, "Source");
            common.SetXml("ServerType", serverType, "Source");
            common.SetXml("ServerType2", serverType2, "Source");
            MessageBox.Show("操作成功！");
        }

        private void glassButton1_Click(object sender, EventArgs e)
        {
            string account = this.ctxtAccount2.Text;
            string dataBase = this.ctxtDatabaseName2.Text;
            string passWord = this.ctxtPassWord2.Text;
            string server = this.ctxtServer2.Text;

            common.SetXml("Server", server, "Target");
            common.SetXml("Account", account, "Target");
            common.SetXml("PassWord", passWord, "Target");
            common.SetXml("DatabaseName", dataBase, "Target");
            MessageBox.Show("操作成功！");
        }


    }
}
